package com.showcai.controller.messageBoard;

import com.showcai.controller.base.WeChatBaseController;
import com.showcai.module.MessageBoard;
import com.showcai.myRunTime.MyRunTimeExcption;
import com.showcai.result.ResultObj;
import com.showcai.result.ReturnCode;
import com.showcai.service.MessageBoardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by Baggio on 2018-1-25.
 */
@RequestMapping("/messageBoard")
@Controller
public class MessageBoardController extends WeChatBaseController {
    @Autowired
    MessageBoardService messageBoardService;
    @RequestMapping(value="/index")
    public ModelAndView index() {
        ModelAndView mov=new ModelAndView();
        String views="index/web/messageBoard/messageBoard";
        if(getIsMobile()){
            views="index/wap/messageBoard/messageBoard";
        }
        mov.setViewName(views);
        return mov;
    }

    @RequestMapping(value="/add")
    @ResponseBody
    public String add(MessageBoard messageBoard) {
        ResultObj resultObj=new ResultObj();
        try {
            messageBoardService.addMessageBoard(messageBoard);
        } catch (MyRunTimeExcption myRunTimeExcption) {
            myRunTimeExcption.printStackTrace();
            resultObj.setCode(ReturnCode.FAIL.getCode());
            resultObj.setMsg(myRunTimeExcption.getMessage());
        }
        return  resultObj.toJson();
    }

}
